package com.example.demo.service.impl;

import com.example.demo.bean.Good;
import com.example.demo.service.BuyStrategy;

import java.math.BigDecimal;

/**
 * @ClassName: DiscountServiceImpl
 * @Description: 打折购买
 * @Author: Administrator
 * @Date: Created in 2022/11/19 15:48
 */
public class DiscountBuyStrategy extends BuyStrategy {

    public BigDecimal calculate(Good good, BigDecimal num) throws Exception {
        if(!good.getIsSalesPromotion()){
            throw new Exception(good.getName() + " is not in sales promotion!");
        }
        return good.getPrice().multiply(good.getDiscount()).multiply(num);
    }
}
